using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Windows.Forms;
using Layout;

namespace CSDesktopUsiXMLRenderer
{
    class UsiXMLWindowRenderer : UsiXMLElementRenderer
    {

        private List<String> layoutManagers = null;

        public UsiXMLWindowRenderer()
        {
            this.layoutManagers = new List<string>();
            this.layoutManagers.Add("flowBox");
            this.layoutManagers.Add("borderBox");
            this.layoutManagers.Add("gridBox");
            this.layoutManagers.Add("gridBagBox");

        }

        public override String getValidElementName(){
            return "window";
        }

        public override Control processRenderization(XmlNode element)
        {
            XmlElement elm = (XmlElement) element;
            String attributeName = elm.GetAttribute("name");
            int attributeWidth = Convert.ToInt16(elm.GetAttribute("width"));
            int attributeHeight = Convert.ToInt16(elm.GetAttribute("height"));

            Form mainForm = new Form();
            mainForm.Name = attributeName;
            mainForm.Width = attributeWidth;
            mainForm.Height = attributeHeight;

            

            foreach (XmlNode node in element.ChildNodes)
            {
                if (this.layoutManagers.Contains(node.Name))
                {

                    (new RendererFactory()).
                             getFirstLayoutManagerRenderer(this.usiXMLInterfaceRenderer).
                                 renderElement(node, ref mainForm);
                }
                else
                {
                }
               
            }

            return mainForm;
        }

        public override UsiXMLElementRenderer getNextRenderer()
        {
            UsiXMLButtonRenderer renderer = new UsiXMLButtonRenderer();
            renderer.setInterfaceRenderer(usiXMLInterfaceRenderer);

            return renderer;

        }
    }
}
